/**
 *2011/01/24
 * 作業者新城	：
 *
 *カートへの書き出し　商品閲覧側
 *
 * */

package shouhin;
import DBs.*;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

//受けとった商品ID（itemID）とイコールの商品情報を商品テーブル(SYOUHIN)から抜き出す
public class PutSQL extends HttpServlet implements Syori{

	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException{
		this.doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
	throws IOException, ServletException{
		//コンテントのタイプとキャラセット
		res.setContentType("text/html; charset=UTF-8;");
		//実行文の格納
		String sql = "select * from syouhin";
		//DBExecのインスタンス
		DBExec dbe = new DBExec();
		dbe.selectTable(sql, new PutSQL(), req, res);
	}

	public void syori(ResultSet rs, HttpServletRequest req, HttpServletResponse res){
		String itemID = req.getParameter("banText");
		//int key =  Integer.parseInt(itemID);
		String numstr = req.getParameter("number");

		try{
			while(rs.next()){
				if(itemID.equals(rs.getString("SYOUHIN_ID"))){							//商品IDをキー
					req.setAttribute("bID", rs.getString("SYOUHIN_ID"));				//商品ＩＤの格納
					req.setAttribute("bNAME", rs.getString("SYOUHINMEI"));		//商品名
					req.setAttribute("bNEDAN", rs.getString("NEDAN"));				//値段
					req.setAttribute("bSETUMEI", rs.getString("SETUMEI"));			//説明
					req.setAttribute("bZAIKO", rs.getString("ZAIKO"));					//説明
					req.setAttribute("bIMG", rs.getString("img_url"));					//イメージＵＲＬ
					req.setAttribute("bNUM", numstr);											//
					// req.setAttribute("bImgs", rs.getString("imgｓ_url"));     		//イメージＵＲＬスモール

				}
			}

		}catch(SQLException e){
			e.printStackTrace();
		}

			RequestDispatcher dp = req
					.getRequestDispatcher("../src/jsp/kessai/cartdev.jsp");

			try {
				dp.forward(req, res);
			} catch (IOException e) {
				e.printStackTrace();
			} catch (ServletException e) {
				e.printStackTrace();
			}


	}
}
